<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>机构人员信息编辑</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:112px;
        }
        .input {
            /*width: 400px;*/
        }
    </style>
</head>
<body>
<div class="mini-fit" style="margin-bottom:40px">
    <form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <!-- 编辑框START-->
        <div id="editform" class="form" style="padding:10px;">
            <input name="id" class="mini-hidden" style="width: 100%;" />
            <#--<input name="create_user" class="mini-hidden" style="width: 100%;"/>-->
            <table class="form-table" align="center" style="width: 80%;margin-left: 50px;" cellspacing="8">
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>姓名:</td>
                    <td>
                        <input name="name" id="name" class="mini-textbox" style="width: 100%" required="true" />
                    </td>

                    <td class="discell"><font color="#dc143c">*</font>性别:</td>
                    <td class="input">
                        <input name="gender" id="gender" class="mini-combobox" required="true"
                               textField="codeName" valueField="codeId" emptyText="请选择..." style="width: 100%;"
                               url="/azbj/inmates/baseinfo/getTbsysCode?codeType=2_2&pcodeId=-1&sn=1"
                        />
                    </td>
                </tr>
                <tr>
                    <td rowspan="2" class="discell"><font color="#dc143c">*</font>民族:</td>
                    <td rowspan="2">
                        <input name="nation" id="nation" class="mini-combobox" style="width: 100%" required="true"
                               textField="codeName" valueField="codeId" popupHeight="170px" emptyText="请选择..."
                               url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=2_4"
                        />
                    </td>
                    <td class="discell">机构人员手机号码:</td>
                    <td>
                        <input name="phone" id="phone" class="mini-textbox" style="width: 100%"
                               emptyText="请输入手机号码" onvaluechanged="checkPhone(2)" />
                    </td>
                </tr>
                <tr>
                    <td class="discell">机构人员固话:</td>
                    <td>
                        <input name="tel" id="tel" class="mini-textbox" style="width: 100%"
                               emptyText="请输入固定电话" onvaluechanged="checkPhone(1)" />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>职务:</td>
                    <td>
                        <input name="duty" id="duty" class="mini-textbox" style="width: 100%" required="true" maxlength="25" />
                    </td>

                    <td class="discell"><font color="#dc143c">*</font>所属机构:</td>
                    <td>
                        <input name="department" id="department" class="mini-textbox" style="width: 100%" required="true" maxlength="25" />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>是否主管领导:</td>
                    <td class="input">
                        <input name="supervisor" id="supervisor" class="mini-radiobuttonlist"
                               data="[{ id: 1, name: '是' },{ id: 2, name: '否' }]"
                               textField="name" valueField="id" value="1" required="true" />
                    </td>

                    <td class="discell"><font color="#dc143c">*</font>是否首页展示:</td>
                    <td class="input">
                        <input name="isshow" id="isshow" class="mini-radiobuttonlist"
                               data="[{ id: 1, name: '是' },{ id: 2, name: '否' }]"
                               textField="name" valueField="id" value="1" required="true" />
                    </td>
                </tr>
            </table>
        </div>
        <!--编辑框END-->
    </form>
</div>
<div style="position: absolute;bottom: 0;line-height:40px;width: 100%;border-top: 1px solid #dfdfdf;text-align: center">
    <#if flog!='1'>
        <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
    </#if>
    <a class="mini-button" iconCls="fa-close" plain="true" onclick="onCancel()">关闭</a>
</div>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");

    //标准方法接口定义
    function SetData(data) {
        var o = mini.decode(data);
        if(o.phone == "无"){
            o.phone = "";
        } else if(o.tel == "无"){
            o.tel = "";
        }
        form.setData(o);
        form.setChanged(false);
        if (${flog!''} === 1) {
            form.setEnabled(false);
        }
    }

    function getTelAndPhone(o) {
        var telAndPhone = o.phone;
        var tel, phone;
        if (telAndPhone !== '' && (/^1[3456789]\d{9}$/.test(telAndPhone))) {
            phone = telAndPhone;
        }
        if (telAndPhone !== '' && /^((0\d{2,3})-?)(\d{7,8})$/.test(telAndPhone)) {
            tel = telAndPhone;
        }
        if (telAndPhone.indexOf("|") !== -1) {
            var a = telAndPhone.split("|");
            tel = a[0];
            phone = a[1];
        }
        return {'tel': tel, 'phone': phone};
    }

    function saveData() {

        //验证非空字段
        form.validate();
        if (form.isValid() === false || ${flog!''} === 1) {
            return;
        }
        var data = form.getData();
        var tel = data.tel;
        var phone = data.phone;
        var newPhone = checkTelAndPhone(tel, phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if (flag) {
            data.phone = newPhone['newTelAndPhone'];
        } else {
            mini.alert("联系电话或手机号有误，请重填");
            return;
        }
        var json = mini.encode(data);
        commonSaveData("/azbj/jgryxx/orgStaffInfo/save", {data: json}, callback);

        // 保存成功的回调函数
        function callback() {
            mini.alert("保存成功", "成功", window.CloseOwnerWindow);
        }
    }

    //电话号码的验证
    function checkPhone(e) {
        var phone = mini.get("phone").getValue();
        var tel = mini.get("tel").getValue();
        if (e == '1') {
            if(tel != '' && !validateTel(tel)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (e == '2') {
            if(phone != '' && !validatePhone1(phone)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }
</script>
</body>
</html>